package com.web.type;

import com.service.ArticleService;
import com.service.ArticleTypeService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DeleteArticleTypeServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ArticleService articleService=new ArticleService();
        ArticleTypeService service=new ArticleTypeService();
        String typename=req.getParameter("typename");

        int count=articleService.querycount(typename);
        if(count==0){
            service.deleteType(typename);
        }else{
            System.out.println("此类型不为空，不能删除！！！");
            req.setAttribute("msg","删除失败！！！");
            req.getRequestDispatcher("/admin/articletype/list.jsp").forward(req,resp);
        }
        req.getRequestDispatcher("/ListType").forward(req, resp);
    }
}
